package com.dreampharos.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

 
/**
 * Copyright 2005 ICOS.CO.KR, Inc. All Rights Reserved.
 * Description:
 *
 * @author 
 * @version
 * @since 
 * Revision:
 */
public class CommUtil extends StringUtil {

    /**
     * "\n"�� "<br>" �� �ٲ۴� , ���ʹ� <br>��ũ�� ��ȯ
     *
     * @param src �ٲ� ���ڿ�
     *
     * @return String �ٲ� ���ڿ�
     */
    public static String lineBreak ( String src ) {
        int len = src.length();
        int linenum = 0, i = 0;

        for ( i = 0; i < len; i++ )
            if ( src.charAt(i) == '\n' )
                linenum++;

        StringBuffer dest = new StringBuffer(len + linenum * 3);

        for ( i = 0; i < len; i++ ) {
            if ( src.charAt(i) == '\n' )
                dest.append("<br>");
            else
                dest.append(src.charAt(i));
        }

        return dest.toString();
    }

    /**
     * null ���ϰ�� ""���� �ٲ۴�
     *
     * @param str null�� �ǽɵǴ� ���ڿ�
     *
     * @return String �ٲ� ���ڿ�
     */
    public static String nullChk ( String str ) {
        return nullChk(str, "");
    }

    /**
     * null �ϰ�� ���ϴ� ���ڷ� replace�Ѵ�.
     * @param str
     * @param newStr
     * @return String
     */
    public static String nullChk ( String str, String newStr ) {
        if ( str == null || str.trim().length() < 1)
            return newStr.trim();
        else
            return str.trim();
    }

    /**
     * null �̰ų� ���ں�ȯ�� �ȵɰ��  0�� ����
     *
     * @param str null�̳� ���ڷ� �ǽɵǴ�  ���ڿ�
     *
     * @return int ���ϴ� ����
     */
    public static double nullChkDouble ( String str ) {
        return nullChkDouble(str, 0);
    }

    public static double nullChkDouble ( String str, int intNum ) {
        try{
            return Double.parseDouble(str);
        }catch(NumberFormatException nf){
            return intNum;
        }
    }


    /**
     * null �̰ų� ���ں�ȯ�� �ȵɰ��  0�� ����
     *
     * @param str null�� �ǽɵǴ� ���ڿ�
     *
     * @return int ���ϴ� ����
     */
    public static int nullChkInt ( String str ) {
        return nullChkInt(str, 0);
    }

    public static int nullChkInt ( String str, int intNum ) {
        try{
            return Integer.parseInt(str);
        }catch(NumberFormatException nf){
            return intNum;
        }
    }

    public static Object nullChkObj(Object obj, Class cls){
        try{
            return (obj==null)? cls.newInstance() : obj;
        }catch(InstantiationException ie){

        } catch (IllegalAccessException e) {

        }

        return null;
    }
    /**
     * ��ü ���ڿ����� �ٲٰ��� �ϴ� ���ڸ� ��� �ٲ۴�
     * replaceStr(����ڿ�, ã������, �ٲܹ���)
     *
     * @param mainStr �ٲ� ����� �ִ� ���ڿ�
     * @param oldStr  ã�� ����
     * @param newStr  �ٲ� ����
     *
     * @return String �ٲ� ���ڿ�
     */
    public static String replaceStr ( String mainStr, String oldStr, String newStr ) {
        String mainString = mainStr;
        String oldString = oldStr;
        String newString = newStr;
        StringBuffer mainSb = new StringBuffer(mainString);
        int i = mainString.lastIndexOf(oldString);
        while ( i >= 0 ) {
            mainSb.replace(i, (i + oldString.length()), newString);
            i = mainString.lastIndexOf(oldString, i - 1);
        }
        return mainSb.toString();
    }

    /**
     * jdk 1.4 �̸��� ���� replaceAll�� ���� ȿ��
     * @param mainStr
     * @param oldStr1
     * @param newStr1
     * @param oldStr2
     * @param newStr2
     * @return
     */
    public static String replaceStr ( String mainStr, String oldStr1, String newStr1, String oldStr2, String newStr2 ) {
        String mainString = mainStr;
        String oldString1 = oldStr1;
        String newString1 = newStr1;
        String oldString2 = oldStr2;
        String newString2 = newStr2;
        StringBuffer mainSb = new StringBuffer(mainString);
        int i = mainString.lastIndexOf(oldString1);
        while ( i >= 0 ) {
            mainSb.replace(i, (i + oldString1.length()), newString1);
            i = mainString.lastIndexOf(oldString1, i - 1);
        }
        mainString = mainSb.toString();
        mainSb = new StringBuffer(mainString);
        i = mainString.lastIndexOf(oldString2);
        while ( i >= 0 ) {
            mainSb.replace(i, (i + oldString2.length()), newString2);
            i = mainString.lastIndexOf(oldString2, i - 1);
        }
        return mainSb.toString();
    }


    /**
     * < �� >�� &lt�� &gt�� �ٲ۴�
     *
     * @param mainStr ����� �Ǵ� ���ڿ�
     *
     * @return String �ٲ� ���ڿ�
     */
    public static String replaceStr ( String mainStr ) {
        String mainString = mainStr;
        String oldString1 = ">";
        String newString1 = "&gt;";
        String oldString2 = "<";
        String newString2 = "&lt;";
        StringBuffer mainSb = new StringBuffer(mainString);
        int i = mainString.lastIndexOf(oldString1);
        while ( i >= 0 ) {
            mainSb.replace(i, (i + oldString1.length()), newString1);
            i = mainString.lastIndexOf(oldString1, i - 1);
        }
        mainString = mainSb.toString();
        mainSb = new StringBuffer(mainString);
        i = mainString.lastIndexOf(oldString2);
        while ( i >= 0 ) {
            mainSb.replace(i, (i + oldString2.length()), newString2);
            i = mainString.lastIndexOf(oldString2, i - 1);
        }
        return mainSb.toString();
    }


    /**
     * ���ڿ��ȿ� html�±׿� �±׻��� ���ڸ� ������ ��ȯ <,>,",'��
     *
     * @param s
     *
     * @return String ������ ���ڿ�
     */
    public static String removeTag ( String s ) {
        final int NORMAL_STATE = 0;
        final int TAG_STATE = 1;
        final int START_TAG_STATE = 2;
        final int END_TAG_STATE = 3;
        final int SINGLE_QUOT_STATE = 4;
        final int DOUBLE_QUOT_STATE = 5;
        int state = NORMAL_STATE;
        int oldState = NORMAL_STATE;
        char[] chars = s.toCharArray();
        StringBuffer sb = new StringBuffer();
        char a;
        for ( int i = 0; i < chars.length; i++ ) {
            a = chars[i];
            switch ( state ) {
                case NORMAL_STATE:
                    if ( a == '<' )
                        state = TAG_STATE;
                    else
                        sb.append(a);
                    break;
                case TAG_STATE:
                    if ( a == '>' )
                        state = NORMAL_STATE;
                    else if ( a == '\"' ) {
                        oldState = state;
                        state = DOUBLE_QUOT_STATE;
                    } else if ( a == '\'' ) {
                        oldState = state;
                        state = SINGLE_QUOT_STATE;
                    } else if ( a == '/' )
                        state = END_TAG_STATE;
                    else if ( a != ' ' && a != '\t' && a != '\n' && a != '\r' && a != '\f' )
                        state = START_TAG_STATE;
                    break;
                case START_TAG_STATE:
                case END_TAG_STATE:
                    if ( a == '>' )
                        state = NORMAL_STATE;
                    else if ( a == '\"' ) {
                        oldState = state;
                        state = DOUBLE_QUOT_STATE;
                    } else if ( a == '\'' ) {
                        oldState = state;
                        state = SINGLE_QUOT_STATE;
                    } else if ( a == '\"' )
                        state = DOUBLE_QUOT_STATE;
                    else if ( a == '\'' )
                        state = SINGLE_QUOT_STATE;
                    break;
                case DOUBLE_QUOT_STATE:
                    if ( a == '\"' )
                        state = oldState;
                    break;
                case SINGLE_QUOT_STATE:
                    if ( a == '\'' )
                        state = oldState;
                    break;
            }
        }
        return sb.toString();
    }

    /**
     * �Խù� ���� ���ڱ��� ����.(�亯�� ���)
     *
     * @param title
     * @param maxNum   �ڰ���� ���� ����
     * @param re_level ��� ����
     *
     * @return String
     */
    public static String getTitleLimit ( String title, int maxNum, int re_level ) {
        int blankLen = 0;
        if ( re_level != 0 ) {
            blankLen = (re_level + 1) * 2;
        }
        int tLen = title.length();
        int count = 0;
        char c;
        int s = 0;
        for ( s = 0; s < tLen; s++ ) {
            c = title.charAt(s);
            if ( (int) (count) > (int) (maxNum - blankLen) ) {
                break;
            }

            if ( c > 127 )
                count += 2;
            else
                count++;
        }
        return (tLen > s) ? title.substring(0, s) + "..." : title;
    }

    /**
     * JDK 1.4 �̸��� ���� split�� ���� ������ �Ѵ�.
     * @param string
     * @param delim
     * @return Stirng[] �ڸ� ���ڿ��� ���� ���� �迭
     */
    public static String[] getSToken ( String string, String delim ) {
        int cnt = 0;
        StringTokenizer stn = new StringTokenizer(string, delim);
        int stn_cnt = stn.countTokens();
        String str[] = new String[stn_cnt];
        while ( stn.hasMoreElements() ) {
            str[cnt] = (String) stn.nextElement();
            cnt++;
        }
        return str;
    }

    /**
     * 10�����϶� �տ� 0�� ���δ�
     * @param num
     * @return String
     */
    public static String belowTen ( int num ) {
        String temp;
        if ( num < 10 ) {
            temp = "0" + num;
        } else {
            temp = "" + num;
        }

        return temp;
    }

    /**
     * ���ڿ� ���ڵ��� �ٲ۴�. euc-kr ���� 8859_1��
     * @param str
     * @return String
     */
    public static String toDB ( String str ) {
        String temp = "";
        if ( str == null ) {
            return "";
        }
        try {
            temp = new String(str.getBytes("euc-kr"), "8859_1");
        } catch ( java.io.UnsupportedEncodingException e ) {
        }
        return temp;
    }

    /**
     * ���ڿ� ���ڵ��� �ٲ۴�. 8859_1 ���� euc-kr��
     * @param str
     * @return String
     */
    public static String fromDB ( String str ) {
        String temp = "";
        if ( str == null ) {
            return "";
        }
        try {
            temp = new String(str.getBytes("8859_1"), "euc-kr");
            temp = str;
        } catch ( java.io.UnsupportedEncodingException e ) {
        }

        return temp;
    }

    /**
     * request �� �Ķ���� ����Ÿ�� ���� �� "" �� ����
     *
     * @param request
     * @param param   �Ķ���͸�
     *
     * @return String
     */
    public static String getParameter ( HttpServletRequest request, String param ) {
        String ret = request.getParameter(param);
        if ( ret == null ) {
            return "";
        }
        return ret;
    }


    /**
     * formatDate.
     *
     * @param date   Date �� ��¥
     * @param format ��¥ ����
     *
     * @return String
     */
    public static String formatDate ( Date date, String format ) {
        if ( date == null || format == null )
            return null;
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }

    /**
     * ������ �ð���ŭ ��Ű ����
     *
     * @param response
     * @param name
     * @param value
     * @param iMinute
     *
     * @throws java.io.UnsupportedEncodingException
     *
     */
    public static void setCookie ( HttpServletResponse response,
                                   String name,
                                   String value,
                                   int iMinute )
        throws java.io.UnsupportedEncodingException {
        Cookie cookie = new Cookie(name, java.net.URLEncoder.encode(value, "euc-kr"));
        cookie.setMaxAge(60 * iMinute);
        cookie.setPath("/");
        response.addCookie(cookie);
    }

    /**
     * ��Ű ����
     *
     * @param response
     * @param name
     * @param value
     *
     * @throws java.io.UnsupportedEncodingException
     *
     */
    public static void setCookie ( HttpServletResponse response,
                                   String name,
                                   String value )
        throws java.io.UnsupportedEncodingException {
        setCookie(response, name, value, 60 * 24 * 15);
    }

    /**
     * ��Ű ��������
     *
     * @param request
     * @param cookieName
     *
     * @return String
     *
     * @throws Exception
     */
    public static String getCookie ( HttpServletRequest request, String cookieName ) throws Exception {
        Cookie[] cookies = request.getCookies();
        if ( cookies == null ) return "";
        String value = "";
        for ( int i = 0; i < cookies.length; i++ ) {
            if ( cookieName.equals(cookies[i].getName()) ) {
                value = java.net.URLDecoder.decode(cookies[i].getValue(), "MS949");
                break;
            }
        }
        return value;
    }

    /**
     * üũ�ڽ� ���� ��� üũ����
     *
     * @param val
     * @param find
     *
     * @return String
     */
    public static String setChecked ( String val, String find ) {
        return val.equals(find) ? "checked" : "";
    }

    /**
     * ����Ʈ ���� ��� ����
     *
     * @param val
     * @param find
     *
     * @return String
     */
    public static String setSelected ( String val, String find ) {
        return val.equals(find) ? "selected" : "";
    }

    /**
     * ���� �ð��� ���˿� ��� ���� ���� *VB�� Now �� ���
     *
     * @param dateFormat yyyy-MM-dd a hh:mm:ss -> 2005-01-08 AM 09:27:20
     *
     * @return String
     */
    public static String Now ( String dateFormat ) {
        Date ToDay = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);

        return sdf.format(ToDay);
    }

    /**
     * Date��ü�� �Ͱ��ְ� ���˿� ��� ���� ���� *VB�� Now �� ���
     *
     * @param dateFormat yyyy-MM-dd a hh:mm:ss -> 2005-01-08 AM 09:27:20
     *
     * @return String
     */
    public static String dateFormat ( String dateFormat, Calendar calendar ) {
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        return sdf.format(calendar.getTime());
    }

    /**
     * ���ڸ� ���ڸ� ���ڸ��� ��ȯ ex) 1 -> 01 *VB�� Format�� ���
     *
     * @param n      ��ȯ�� ��
     * @param length �ڸ��� ũ��
     *
     * @return
     */
    public static String Format ( int n, int length ) {
        n = n + (int) Math.pow(10, length);
        String ret = String.valueOf(n);
        return new String(ret.substring(1));
    }

    /**
     * �⵵�� ���� select�� option�� ���� ����
     *
     * @param val Ư�� option�� �����ϰ��� �� �� value ���� ����
     *
     * @return
     */
    public static String getSelYear ( String val ) {
        int i;
        StringBuffer src = new StringBuffer("");

        if ( val.equals("") ) val = CommUtil.Now("yyyy");

        for ( i = 1970; i <= 2100; i++ ) {
            src.append("<option value=\"" + i + "\" " + CommUtil.setSelected(i + "", val) + ">" + i + "</option>\r\n");
        }

        return src.toString();
    }

    /**
     * �� ���� select�� option�� ���� ����
     *
     * @param val Ư�� option�� �����ϰ��� �� �� value ���� ����
     *
     * @return
     */
    public static String getSelMonth ( String val ) {
        int i;
        String fmt = "";
        StringBuffer src = new StringBuffer("");

        if ( val.equals("") ) val = CommUtil.Now("MM");

        for ( i = 1; i <= 12; i++ ) {
            fmt = CommUtil.Format(i, 2);
            src.append("<option value=\"" + fmt + "\" " + CommUtil.setSelected(fmt, val) + ">" + fmt + "</option>\r\n");
        }

        return src.toString();
    }

    /**
     * ���ڿ� ���� select�� option�� ���� ����
     *
     * @param val Ư�� option�� �����ϰ��� �� �� value ���� ����
     *
     * @return
     */
    public static String getSelDay ( String val ) {
        int i;
        String fmt = "";
        StringBuffer src = new StringBuffer("");

        if ( val.equals("") ) val = CommUtil.Now("dd");

        for ( i = 1; i <= 31; i++ ) {
            fmt = CommUtil.Format(i, 2);
            src.append("<option value=\"" + fmt + "\" " + CommUtil.setSelected(fmt, val) + ">" + fmt + "</option>\r\n");
        }

        return src.toString();
    }

    /**
     * ��, ��, �Ͽ� ���� ���ϰų� ���� ��¥�� ��ȯ�޴´�
     * @param yy +- int
     * @param mm +- int
     * @param dd +- int
     * @return  String yyyy-MM-dd ����� ��¥
     */
    public static String modifyDate(int yy, int mm, int dd){

        return modifyDate(yy, mm, dd,"yyyy-MM-dd");
    }

    /**
     * ��, ��, �Ͽ� ���� ���ϰų� ���� ��¥�� ������Ŀ� ���༭ ��ȯ�޴´�
     * @param yy +- int
     * @param mm +- int
     * @param dd +- int
     * @param format ex)yyyy-MM-dd
     * @return ������Ŀ� �´� ��¥�� ��ȯ
     */
    public static String modifyDate(int yy, int mm, int dd, String format){
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.YEAR, yy);
        calendar.add(Calendar.MONTH, mm);
        calendar.add(Calendar.DATE, dd);
        return dateFormat(format,calendar);
    }
    
    /**
     * ��, ��, �Ͽ� ���� ���ϰų� ���� ��¥�� ������Ŀ� ���༭ ��ȯ�޴´�
     * @param yy +- int
     * @param mm +- int
     * @param dd +- int
     * @param format ex)yyyy-MM-dd
     * @return ������Ŀ� �´� ��¥�� ��ȯ
     */
    public static String modifyDate2(int yy, int mm, int dd, String format){
        Calendar calendar = Calendar.getInstance();
        
        calendar.set(yy , mm -1, dd);
        return dateFormat(format,calendar);
    }

    public static String getTime(){
        String tempValue = (new SimpleDateFormat("yyyyMMddHHmmss")).format( new Date() );

        return tempValue.substring(8);
    }

    public static void main(String[] args){
        /*System.out.println(Now("yyyyMMdd"));
        System.out.println(modifyDate(0, 0, 0));
        System.out.println(modifyDate(1, 0, 0));
        System.out.println(modifyDate(0, 1, 0));
        System.out.println(modifyDate(0, 0, 1));

        System.out.print(Integer.parseInt("20041234".substring(0,4)) +" : ");
        System.out.print(Integer.parseInt("20041234".substring(4,6))+" : ");
        System.out.print(Integer.parseInt("20041234".substring(6,8)));

        System.out.print(dateFormat("20050611", "yyyy.MM.dd"));*/

        System.out.println("time : " + getTime().substring(8));
    }

    /** ���� Ȯ���ڸ� ���ϱ�
     *  @param fileName
     *  @return String ���� Ȯ���� �̸�
     */
    public static String getFileExt(String fileName)
    {
        String value = new String();
        int start = 0;
        int end = 0;
        if(fileName == null)
        {
            return null;
        } else
        {
            start = fileName.lastIndexOf('.') + 1;
            end = fileName.length();
            value = fileName.substring(start, end);
            return value;
        }
    }


    /**
    * ���� �����ϱ�
    * @param fileName
    * @param path
    * @return
    */
   public static boolean deleteFile(String fileName, String path){
        System.out.println("fileName"+fileName);
        System.out.println("path"+path); 
        boolean delOk = true;
        try{
            new File(path + "/" + fileName).delete();
        }catch(Exception e){
           System.out.println(e.getMessage());
           delOk = false;
        }
        return delOk;
   }

    public static String dateFormat(String date, String format){
    	String retVal = "";
    	
        if(date == null || "".equals(date)){
            return "";
        }else if(date.indexOf(".") > 0 || date.indexOf("-") > 0 || date.indexOf("/") > 0){
            return date;
        }
        
        try {
	        Calendar carCalendar = Calendar.getInstance();
	        carCalendar.set(Integer.parseInt(date.substring(0,4)), Integer.parseInt(date.substring(4,6))-1 , Integer.parseInt(date.substring(6,8)));
	        retVal = dateFormat(format ,carCalendar);
        }catch(Exception e){
        	retVal = date;
        }
        
        return retVal;
    }

    /**
     *  ������� ����
     * @param str
     * @return
     */
    public static String eRateFormat(String str){
        String temp = null;
        if(str == null){
            temp = "0";
        }else if(str.equals("")){
            temp = "";            
        }else{
            double change = Double.valueOf(str.trim()).doubleValue();
            DecimalFormat decimal = new DecimalFormat("###,###,###.##");
            temp = decimal.format(change);
        }
        return temp;
    }

    /**
     *  ������� ����
     * @param str
     * @return String
     */
    public static String eRateFormat(String str, String format){
        String temp = null;
        if(str == null){
            temp = "0";
        }else{
            double change = Double.valueOf(str.trim()).doubleValue();
            DecimalFormat decimal = new DecimalFormat(format);
            temp = decimal.format(change);
        }
        return temp;
    }

    /**
     *  ������� ����
     * @param str
     * @return String
     */
    public static String eRateFormat(String str, String format, String ment){
        String temp = null;
        if(str == null){
            temp = "0";
        }else{
            try{
                double change = Double.valueOf(str.trim()).doubleValue();
                DecimalFormat decimal = new DecimalFormat(format);
                temp = decimal.format(change);
            }catch(Exception e){
                //System.out.println(e);
                return ment;
            }
        }
        return temp;
    }


    public static String eRateFormat2(String str, String format, String ment){
        String temp = null;
        if(str == "" || str == null){
            temp = "";
        }else{
            try{
                double change = Double.valueOf(str.trim()).doubleValue();
                DecimalFormat decimal = new DecimalFormat(format);
                temp = decimal.format(change);
            }catch(Exception e){
                //System.out.println(e);
                return ment;
            }
        }
        return temp;
    }

    /**
     * �Ѿ�� ��δ�� ����� �������� ������ ����� �����.
     * @param path
     * @return boolean ����θ� ��ȯ
     * @throws Exception
     */
    private boolean makeDir(String path) throws Exception {
        File f = new File(path);
        if (f.exists() == false) return f.mkdir();
        return false;
    }    
    
    /**
     * 0���� ������ �ϱ�.
     * @param srcStr
     * @param max
     * @return
     */
    public static String fullZero(String srcStr, int max){
        if(srcStr.length()<max){
          for(int i=srcStr.length(); i<max; i++){
               srcStr="0"+srcStr;
          }
        }

        return srcStr;
    }

    /**
     * String�� ���̰� �� ��� ...���� ó��
     * @param srcStr
     */

    public static String  reduceString(String srcStr,int num){
        srcStr = CommUtil.nullChk(srcStr);
        String makeString="";
        if(srcStr.length()>num){
           makeString=srcStr.substring(0,num-1)+"..";
        }else{
           makeString=srcStr;
        }

        return makeString;
    }
    
    /**
     * 
     * ���ε� �� ���ϸ� ���� ������ ����� �ø��� ���� ������ ���� �Ѵ�. 
     * 
     * @param tempPath ������� ���
     * @param filePath ���� ���� ��� ���
     * @param upFileName ���� ������ ���� �̸�
     * @param delFileName ���� �� ���� �̸�
     * @throws Exception
     */
    
    public static void upLoadFile(String tempPath, String filePath, String upFileName, String delFileName) throws Exception {
    	
    	mDir(filePath);
    	
    	fileDelete(filePath, delFileName);
    	
    	fileUpLoad(tempPath, filePath, upFileName);
    	
    	fileDelete(tempPath, upFileName);
    	
    }
    
    public static void upLoadFile(String tempPath, String filePath, String upFileName) throws Exception {
    	mDir(filePath);

    	fileUpLoad(tempPath, filePath, upFileName);
    	
    	fileDelete(tempPath, upFileName);
    	
    }
    
    public static void fileUpLoad(String tempPath, String filePath, String fileName) throws Exception {
    	int readByte = 0;

    	FileInputStream tempF 	= new FileInputStream(tempPath + fileName);
    	FileOutputStream f		= new FileOutputStream(filePath + fileName);
    	while((readByte = tempF.read())!=-1) f.write(readByte);
    	
    	tempF.close();
		f.close();
    }
    
    public static void fileDelete(String tempPath, String fileName) throws Exception {
    	File file = new File(tempPath + fileName);
    	file.delete();
    }
    
    public static void mDir(String filePath)throws Exception {
    	String[] path = filePath.split("/");
    	String spath = path[0]; 
    	for(int i=1; i < path.length; i++){
    		spath = spath+ "/" + path[i];
	    	File tpath = new File(spath);
	    	
	    	if (tpath.exists() == false){ 
	    		tpath.mkdir();
	    	}
    	}
    }

    public static String readFile(String fileName) {
    	String temp = "";
    	temp.replaceAll("", "11");
    	StringBuffer sb = new StringBuffer () ;
    	try {
            BufferedReader br = new BufferedReader (new FileReader (fileName)) ;
            String tempString = null ;
            while ((tempString = br.readLine ()) != null) {
                sb.append (tempString) ;
                sb.append ("\n") ;
            }
            br.close () ;
            br = null ;
        } catch (Exception e) {
            e.printStackTrace () ;
        }
        return sb.toString ();
    }


    /**
     * ������ ?�� �ش��ϴ� �������� ������ ? �� ������ ġȯ�� ������ �����ش�
     * LoggagleStatement �� �ִ���� Connection ���� ���� �ֵ����Ѱ���.
     * by �����
     * @param Query ?�� �ִ� ����
     * @param param ? �� �ش��ϴ� ������ ���� Array (������ ? �� ��� param�� �� ���ƾ� �Ѵ�.)
     * @return String  ? �� ������ ġȯ�� ���� ��ȯ
     */
    public static String getQueryString(String Query, ArrayList param) {
        ArrayList parameterValues = new ArrayList();
        for(int i = 0 ; i < param.size() ; i++){
            saveQueryParamValue(i+1, param.get(i), parameterValues);
        }

        StringBuffer buf = new StringBuffer();
        int qMarkCount = 0;
        StringTokenizer tok = new StringTokenizer(Query + " ", "?");
        while (tok.hasMoreTokens()) {
            String oneChunk = tok.nextToken();
            buf.append(oneChunk);

            try {
                Object value;
                if (parameterValues.size() > 1 + qMarkCount) {
                    value = parameterValues.get(1 + qMarkCount++);
                } else {
                    if (tok.hasMoreTokens()) {
                        value = null;
                    } else {
                        value = "";
                    }
                }
                buf.append("" + value);
            } catch (Throwable e) {
                buf.append("ERROR WHEN PRODUCING QUERY STRING FOR LOG."
                        + e.toString());
                // catch this without whining, if this fails the only thing wrong is probably this class
            }
        }
        return buf.toString().trim();
    }

    /**
     * ? �� �ش��ϴ� ������ Ÿ�Ժ��� '' �� �ٿ��� ���� �Ǵ� �׳� ���ڷ� �����Ѵ�.
     * @param position ġȯ�� ? �� �� 1 ���� ����
     * @param obj ? �� ġȯ�� ���� Object ����̴�
     * @param parameterValues ġȯ�� ���� ���� Array
     */
    private static void saveQueryParamValue(int position, Object obj, ArrayList parameterValues) {
         String strValue;
         if (obj instanceof String || obj instanceof Date) {
             // if we have a String or Date , include '' in the saved value
             strValue = "'" + obj + "'";
         } else {

             if (obj == null) {
                 // convert null to the string null
                 strValue = "null";
             } else {
                 // unknown object (includes all Numbers), just call toString
                 strValue = obj.toString();
             }
         }

         // if we are setting a position larger than current size of parameterValues, first make it larger
         while (position >= parameterValues.size()) {
             parameterValues.add(null);
         }
         // save the parameter
         parameterValues.set(position, strValue);
     }

    /**
     * �Ѿ�� �Ķ���� ���� Console ���� Ȯ��
     * @param request �Ѿ�� Request �� �ѱ��.
     */
    public static void checkPrameter(HttpServletRequest request) {
        Hashtable hpam = new Hashtable();
        Enumeration penums;
        String name = "";
        String value = "";

        for (penums = request.getParameterNames(); penums.hasMoreElements();) {
            name = penums.nextElement().toString();
            value =( (value = request.getParameter(name)) == null ) ? "" : value;

            hpam.put(name.trim(), value.trim());
            System.out.println("check parameter - name : " + name + " : " + value);
        }
    }
    
	
    public static String compareData(String value,float compData){
    	  String msg1 ="Ʃ��or�����ʿ�";
          String msg2 ="����� ����";
          String rtnValue="";

          if(value==null || "".equals(value)){
        	  rtnValue="";
          }else{
	          float avg = Float.parseFloat(value);	          
	          if(avg==-99){
	        	  rtnValue="";
              }else if(avg>=compData){
	        	  rtnValue=msg1;
	          }else{
	        	  rtnValue=msg2;
	          }//if
          }//if
          
    	return rtnValue;
    }
    
    
    /**
     * ���ڿ� ���ڵ��� �ٲ۴�. 8859_1 ���� MS949�� 
     * @param str
     * @return String
     */
    public static String toKor ( String str ) {
        String temp = "";
        if ( str == null ) {
            return "";
        }
        try {
            temp = new String(str.getBytes("8859_1"), "MS949");
        } catch ( java.io.UnsupportedEncodingException e ) {
        }
        return temp;
    }
    /**
     * ���ڿ� ���ڵ��� �ٲ۴�. 8859_1 ���� MS949�� 
     * @param str
     * @return String
     */
    public static String toKor1 ( String str ) {
        String temp = "";
        if ( str == null ) {
            return "";
        }
        try {
            temp = new String(str.getBytes("uft-8"), "MS949");
        } catch ( java.io.UnsupportedEncodingException e ) {
        }
        return temp;
    }
    /**
     * ���ڿ� ���ڵ��� �ٲ۴�. MS949���� 8859_1��  
     * @param str
     * @return String
     */
    public static String toKorOrg ( String str ) {
        String temp = "";
        if ( str == null ) {
            return "";
        }
        try {
            temp = new String(str.getBytes("MS949"), "8859_1");
        } catch ( java.io.UnsupportedEncodingException e ) {
        }
        return temp;
    }
    
    
  
    
   
}